/**
 * Definition for singly-linked list.
 * function ListNode(val, next) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.next = (next===undefined ? null : next)
 * }
 */
//整道题坐下来有几点要注意和补充的细节，如果就只有1，1的话那么还需要保存它的前面 所以保存是有必要的 
/**
 * @param {ListNode} head
 * @return {ListNode}
 */
var deleteDuplicates = function (head) {
  let flag = new ListNode()
  flag.next = head
  let cur = flag
  while (cur.next && cur.next.next) {
    if (cur.next.val === cur.next.next.val) {
      let val = cur.next.val
      while (cur.next && cur.next.val === val) {
        cur.next = cur.next.next
      }
    }
    else {
      cur = cur.next
    }
  }
  return flag.next
};